package com.superzqb.asus.superzqbFragment.superzqbShopQrcode.image;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.superzqb.asus.superzqbFragment.superzqbShopQrcode.image.ImageLoader.Type;

import com.superzqb.asus.superzqb.R;

import java.util.List;

public class ListviewAdapter extends BaseAdapter {
	private Context mContext;
	private List<ImageFloder> mDatas;
	private int selectedPosition=1;
	public static ViewGroup v=null;
	private Boolean b=true;
	public ListviewAdapter(Context mcontext, List<ImageFloder> mdatas){
		this.mContext=mcontext;
		this.mDatas=mdatas;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return (mDatas==null)?0:mDatas.size(); 
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mDatas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}
	public void setSelectedPosition(int position) {
		selectedPosition = position;  
		}  

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		DIR viewHolder=null;
		if(arg1==null){  
            //Log.d("MyBaseAdapter", "�½�convertView,position="+position);  
            arg1 = LayoutInflater.from(mContext).inflate(
            		R.layout.photo_item, null);
              
            viewHolder = new DIR();  
            viewHolder.al = (ImageView)arg1.findViewById(R.id.abimageView);
            viewHolder.name= (TextView)arg1.findViewById(R.id.abname);
            viewHolder.count= (TextView)arg1.findViewById(R.id.abcount);
            viewHolder.choose = (ImageView)arg1.findViewById(
                    R.id.choseimage); 
            arg1.setTag(viewHolder);  
        }else{  
            viewHolder = (DIR)arg1.getTag();  
            //Log.d("MyBaseAdapter", "�ɵ�convertView,position="+position); 
            
        }
		viewHolder.name.setText(mDatas.get(arg0).getName());
		//mDatas.get(arg0).setFlag(false);
		//System.out.println(mDatas.get(arg0).getFirstImagePath());
		ImageLoader.getInstance(3, Type.LIFO).loadImage(mDatas.get(arg0).getFirstImagePath(), viewHolder.al);
		viewHolder.count.setText(""+mDatas.get(arg0).getCount());
		v=arg2;
		if (mDatas.get(arg0).getFlag()) {
			//System.out.println("-------"+mDatas.get(arg0).getFirstImagePath());
			
			arg1.setBackgroundColor(Color.parseColor("#87CEFF"));
		
			//viewHolder.choose.setImageDrawable(mContext.getResources().getDrawable(R.drawable.pictures_selected));
		}else{
			arg1.setBackgroundColor(0);
		}
		//System.out.println("-------+++++++++"+mDatas.get(arg0).getFlag());
		
		return arg1;
	}
	class DIR{
		ImageView al;
		TextView name;
		TextView count;
		ImageView choose;
	}

}
